<template>
  <nav-bar />
  <van-tabs
    v-model:active="active"
    title-active-color="#F8124A"
    animated
    swipeable
    @click-tab="onClickTab"
  >
    <van-tab v-for="index in 6" :key="index" :title="'选项 ' + index">
      <van-list finished-text="没有更多了" :finished="loadState" @load="onLoad">
        <div v-for="item in num.list.length" :key="item" class="list" @click="jump">
          <div class="order flexC">{{ item }}</div>
          <div class="article">
            <!-- 标题 -->
            <div class="title"> 标题 </div>
            <!-- 内容 -->
            <div class="detail"> 内容 </div>
            <!-- 作者 -->
            <div class="info">
              <div class="author">
                <SvgIcon name="email" :size="15" />
                沐歌
              </div>
              <div class="time">
                <SvgIcon name="email" :size="15" />
                2012/12/16
              </div>
              <div class="visited">
                <SvgIcon name="email" :size="15" />
                999+
              </div>
            </div>
          </div>
        </div>
      </van-list>
    </van-tab>
  </van-tabs>
</template>

<script lang="ts" setup>
  import { reactive, ref } from 'vue'
  import SvgIcon from '@comp/SvgIcon/index.vue'
  import NavBar from '@comp/Navbar/Navbar.vue'
  import { useRouter } from 'vue-router'
  const active = ref<number>(0)
  const loadState = ref<boolean>(false)
  const num = reactive({ list: [1, 2, 3, 4, 5] })
  // 创建路由实例
  const router = useRouter()
  const jump = () => {
    router.push('/blogDetail')
  }
  const onClickTab = ({ name, title }: any) => {
    console.log(name, title)
    loadState.value = false
  }
  const onLoad = () => {
    console.log('lower')
    // setTimeout(() => {
    num.list.push(...[1, 2, 3, 5, 6])
    // }, 200)
    if (num.list.length > 20) {
      setTimeout(() => {
        loadState.value = true
      }, 200)
    }
  }
</script>
<style lang="scss" scoped>
  .list {
    display: flex;
    padding: 10px;
    border-bottom: 1px groove #fd8c84;
    border-radius: 8px;

    .order {
      border: 1px solid transparent;
      background-color: #fd8c84;
      color: #fffdef;
      padding: 2px 5px;
      margin-right: 10px;
      max-height: 12.5px;
    }

    .article {
      width: 100%;

      .title {
        display: flex;
        padding-right: 20px;
        width: 97%;
        font-size: $blog-text-size;
        color: $nav-bar-title-color;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
      }

      .detail {
        flex: 1;
        margin-top: $nav-bar-marginTop;
        margin-bottom: $nav-bar-marginTop;
        font-size: $blog-text-size;
        color: $nav-bar-detail-color;
        white-space: normal;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        word-break: break-all;
        background-color: red;
      }

      .info {
        display: flex;
        font-size: 15px;
        margin-top: $nav-bar-marginTop;
        color: $nav-bar-detail-color;

        .time,
        .author,
        .visited {
          margin-right: 20px;
        }
      }
    }
  }
</style>
<style>
  .van-tab__pane {
    height: calc(100vh - 79px);
    overflow: auto;
  }

  .van-tab--active {
    font-weight: 600;
  }
</style>
